package com.ruoyi.system.service.impl.processServiceImpl;


import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.process.ProcessAbnormal;
import com.ruoyi.system.mapper.process.ProcessAbnormalMapper;
import com.ruoyi.system.service.processService.IProcessAbnormalService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 加工异常Service业务层处理
 * 
 * @author ljx
 * @date 2020-07-06
 */
@Service
public class ProcessAbnormalServiceImpl implements IProcessAbnormalService
{
    @Resource
    private ProcessAbnormalMapper processAbnormalMapper;

    /**
     * 查询加工异常
     * 
     * @param id 加工异常ID
     * @return 加工异常
     */
    @Override
    public ProcessAbnormal selectProcessAbnormalById(Long id)
    {
        ProcessAbnormal abnormal = new ProcessAbnormal();
        abnormal.setId(id);
        List<ProcessAbnormal> object = processAbnormalMapper.getObjectWithInvent(abnormal);
        if(CollectionUtils.isNotEmpty(object)){
            abnormal = object.get(0);
        }else{
            abnormal.setId(null);
        }
        return abnormal;
    }

    /**
     * 查询加工异常列表
     * 
     * @param processAbnormal 加工异常
     * @return 加工异常
     */
    @Override
    public List<ProcessAbnormal> selectProcessAbnormalList(ProcessAbnormal processAbnormal)
    {
        return processAbnormalMapper.getObjectWithInvent(processAbnormal);
    }

    /**
     * 新增加工异常
     * 
     * @param processAbnormal 加工异常
     * @return 结果
     */
    @Override
    public int insertProcessAbnormal(ProcessAbnormal processAbnormal)
    {
        processAbnormal.setCreateTime(DateUtils.getNowDate());
        return processAbnormalMapper.insertProcessAbnormal(processAbnormal);
    }

    /**
     * 修改加工异常
     * 
     * @param processAbnormal 加工异常
     * @return 结果
     */
    @Override
    public int updateProcessAbnormal(ProcessAbnormal processAbnormal)
    {
        processAbnormal.setUpdateTime(DateUtils.getNowDate());
        return processAbnormalMapper.updateProcessAbnormal(processAbnormal);
    }

    /**
     * 删除加工异常对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteProcessAbnormalByIds(String ids)
    {
        return processAbnormalMapper.deleteProcessAbnormalByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除加工异常信息
     * 
     * @param id 加工异常ID
     * @return 结果
     */
    @Override
    public int deleteProcessAbnormalById(Long id)
    {
        return processAbnormalMapper.deleteProcessAbnormalById(id);
    }
}
